<template>
  <n-tabs justify-content="space-evenly" type="line">
    <n-tab-pane name="o1" tab="绑定群信息">
      <div class="_box0">
        <n-scrollbar x-scrollable x-placement="top">
          <div class="_list">
            <div class="_listbox">
              <div style="width: 100px" class="_df">绑定类型</div>
              <div style="width: 255px" class="_df">绑定人opid</div>
              <div style="width: 255px" class="_df">绑定频道/群opid</div>
              <div style="width: 125px" class="_df">绑定模式</div>
              <div style="width: 125px" class="_df">操作</div>
            </div>

            <div style="margin-top: 4px; display: flex; flex-direction: column; gap: 8px">
              <template v-for="item in data.d.group">
                <div class="_rolebox" style="height: 45px; font-size: 12px">
                  <div style="width: 100px" class="_df">
                    {{ item.bottype }}
                  </div>
                  <div style="width: 255px" class="_df">
                    {{ item.authorid }}
                  </div>
                  <div style="width: 255px" class="_df">
                    {{ item.groupid }}
                  </div>
                  <div style="width: 125px" class="_df">
                    模式：{{ item.botmode ?? 0 }} <br />独绑：{{ item.one ?? 0 }}
                  </div>
                  <div style="width: 125px" class="_df">
                    <n-button @click="set.del_guild_bind(item._id.$oid)"
                      >删除绑定</n-button
                    >
                  </div>
                </div>
              </template>
            </div>
          </div>
        </n-scrollbar>
      </div>
    </n-tab-pane>
    <n-tab-pane name="o2" tab="默认公会绑定群信">
      <div class="_box0">
        <n-scrollbar x-scrollable x-placement="top">
          <div class="_list">
            <div class="_listbox">
              <div style="width: 100px" class="_df">绑定类型</div>
              <div style="width: 255px" class="_df">绑定人opid</div>
              <div style="width: 255px" class="_df">绑定频道/群opid</div>
              <div style="width: 125px" class="_df">操作</div>
            </div>

            <div style="margin-top: 4px; display: flex; flex-direction: column; gap: 8px">
              <template v-for="item in data.d.guild_def">
                <div class="_rolebox" style="height: 45px; font-size: 12px">
                  <div style="width: 100px" class="_df">
                    {{ item.bottype }}
                  </div>
                  <div style="width: 255px" class="_df">
                    {{ item.authorid }}
                  </div>
                  <div style="width: 255px" class="_df">
                    {{ item.groupid }}
                  </div>
                  <div style="width: 125px" class="_df">
                    <n-button @click="set.del_guild_def_bind(item._id.$oid)"
                      >删除绑定</n-button
                    >
                  </div>
                </div>
              </template>
            </div>
          </div>
        </n-scrollbar>
      </div>
    </n-tab-pane>
    <n-tab-pane name="o3" tab="公会成员绑定信息">
      <div class="_box0">
        <n-scrollbar x-scrollable x-placement="top">
          <div class="_list">
            <div class="_listbox">
              <div style="width: 100px" class="_df">绑定类型</div>
              <div style="width: 255px" class="_df">QQ/频道opid</div>
              <div style="width: 255px" class="_df">Q群/频道opid</div>
              <div style="width: 125px" class="_df">角色名称</div>
              <div style="width: 125px" class="_df">操作</div>
            </div>

            <div style="margin-top: 4px; display: flex; flex-direction: column; gap: 8px">
              <template v-for="item in data.d.user">
                <div class="_rolebox" style="height: 45px; font-size: 12px">
                  <div style="width: 100px" class="_df">
                    {{ item.bottype }}
                  </div>
                  <div style="width: 255px" class="_df">
                    {{ item.authorid }}
                  </div>
                  <div style="width: 255px" class="_df">
                    {{ item.groupid }}
                  </div>
                  <div style="width: 125px" class="_df">
                    {{ item.user_name }}
                  </div>
                  <div style="width: 125px" class="_df">
                    <n-button @click="set.del_user_bind(item._id.$oid)"
                      >删除绑定</n-button
                    >
                  </div>
                </div>
              </template>
            </div>
          </div>
        </n-scrollbar>
      </div>
    </n-tab-pane>
  </n-tabs>
</template>

<script>
import { cfg } from "@/cfg/cfg.js";

export default {
  props: {
    guild: {
      type: Object,
      required: true,
    },
  },
  setup(props) {
    const guild = props.guild;

    const set = {
      //删除公会_默认绑定
      del_guild_def_bind: async (id) => {
        try {
          const res = await cfg.axios.get(`${cfg.url}`, {
            params: {
              t: "v2/get",
              t2: "admin/guild",
              t3: "del_guild_def_bind",
              id: id,
              uid: cfg.user.uid,
              authkey: cfg.user.authkey,
            },
          });
          if (res.data.code == 0) {
            await set.get_list(guild);
          } else {
            cfg.alert.error({
              title: "ERROR！",
              content: `${res.data.msg}`,
            });
          }
        } catch (error) {
          cfg.alert.error({
            title: "ERROR！",
            content: `${error}`,
          });
        }
      },
      //删除公会绑定
      del_guild_bind: async (id) => {
        try {
          const res = await cfg.axios.get(`${cfg.url}`, {
            params: {
              t: "v2/get",
              t2: "admin/guild",
              t3: "del_guild_bind",
              id: id,
              uid: cfg.user.uid,
              authkey: cfg.user.authkey,
            },
          });
          if (res.data.code == 0) {
            await set.get_list(guild);
          } else {
            cfg.alert.error({
              title: "ERROR！",
              content: `${res.data.msg}`,
            });
          }
        } catch (error) {
          cfg.alert.error({
            title: "ERROR！",
            content: `${error}`,
          });
        }
      },
      //删除用户绑定
      del_user_bind: async (id) => {
        try {
          const res = await cfg.axios.get(`${cfg.url}`, {
            params: {
              t: "v2/get",
              t2: "admin/guild",
              t3: "del_user_bind",
              id: id,
              uid: cfg.user.uid,
              authkey: cfg.user.authkey,
            },
          });
          if (res.data.code == 0) {
            await set.get_list(guild);
          } else {
            cfg.alert.error({
              title: "ERROR！",
              content: `${res.data.msg}`,
            });
          }
        } catch (error) {
          cfg.alert.error({
            title: "ERROR！",
            content: `${error}`,
          });
        }
      },
      //获取列表
      get_list: async (g) => {
        try {
          const res = await cfg.axios.get(`${cfg.url}`, {
            params: {
              t: "v2/get",
              t2: "admin/guild",
              t3: "bind_list",
              id: g._id.$oid,
              uid: cfg.user.uid,
              authkey: cfg.user.authkey,
            },
          });
          data.d = res.data.data;
        } catch (error) {
          cfg.alert.error({
            title: "ERROR！",
            content: `${error}`,
          });
        }
      },
    };
    let data = reactive({
      d: {},
    });

    onMounted(async () => {
      await set.get_list(guild);
    });
    return {
      guild,
      data,
      cfg,
      set,
    };
  },
};
</script>
